package demo;

import java.util.concurrent.CountDownLatch;

/**
 * @author ：黄淼淳
 * @date ：2021/12/18 16:23
 * @description：
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        /*CountDownLatch count = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"离开教室!!!!");
                count.countDown();
            },String.valueOf(i+1)).start();
        }
        count.await();
        System.out.println("班长关门了!!!!");*/
        CountDownLatch count = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"离开教室了！！！");
                count.countDown();
            },String.valueOf(i+1)).start();
        }
        if (count.getCount()!=0)
            count.await();
        System.out.println("班长把门锁了！！！");
    }
}
